<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
error_reporting(E_ALL & ~E_NOTICE);
ini_set ('display_errors', 'On');
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
# 根目錄
define('ROOT_DIR'	 	,str_replace('\\','/',dirname(__FILE__)).'/');
# 当前执行脚本的绝对路径名
define('FILE_DIR'	 	,str_replace(ROOT_DIR,'',str_replace('\\','/',dirname($_SERVER['SCRIPT_FILENAME'])).'/'));
# 配制文件的目录
define('CONFIG_DIR'	 	,ROOT_DIR.'_config/');
# 内核文件目录
define('CORE_DIR'	 	,ROOT_DIR.'_core/');
# 模板	
define('TPL_DIR'	 	,'Dtpl/');
define('TPL_ROOT_DIR'	,ROOT_DIR.TPL_DIR);
define('TPL_CACHE_TIME'	,3600);
# 包含配制文件
require CONFIG_DIR.'all.conf.php';
require CONFIG_DIR.'local.conf.php';
# 必包类
/**
 * @abstract PHP 快捷函数
 */
function &O(&$o){return $o;};
function &A(&$a,$k){return $a[$k];};
function &E($a,$t=0){trigger_error($a,$t?E_USER_ERROR:E_USER_WARNING);};
/**
 * @abstract Autoload Function
 */ 
function __autoload($class) 
{
	$class = str_replace('_','/',$class);
	$filename = CORE_DIR.$class.'.class.php';
	if(file_exists($filename))
	{
		include $filename;
	}else
	{
		$filename = ADMIN_CORE_DIR.$class.'.class.php';
		if(ADMIN_CORE_DIR  && file_exists($filename))
		{
			include $filename;
		}
	}	
}
/**
 * 功能:得當前用戶名
 * 參數:無
 * 返回:用戶名
 */
function u_get_urs()
{
	$urs 			= $_COOKIE['urs'];
	$pass_hex		= $_COOKIE['pass_hex'];
	$login_hex 		= $_COOKIE['login_hex'];
	return (md5(substr(base64_encode($urs . SITE_LOGINKEY . $pass_hex), strlen(SITE_LOGINKEY)%5, -1)) == $login_hex)
				?$urs
				:false;
}
/**
 * 基类
 */
class ObjectBase 
{
	public $stpl;
	public $scfg;
	public $ws;
	public function ws($config=array(),$arr=array())
 	{
 		require CORE_DIR.'ws.class.php';
 		$ws_parameter = $_GET["dy"];
 		$ws_config 	  = array(
							'dir'		=>method,//目录
					 		'minSize'	=>$config['minSize']?$config['minSize']:1024,
					 		'level'		=>(int)$config['level'],
					 		'cacheTime' =>$config['cacheTime']?$config['cacheTime']:3600,
					 		'outEnd'    =>$config['outEnd']?$config['outEnd']:'.html'
					 	);
		$ws_arr 	 = $arr?$arr:array(method=>1);
 		$this->ws 	 = &new ws($ws_arr,$ws_config,$ws_parameter);
 	}
 	public function init()
 	{
 	    global $scfg;
 	    require CORE_DIR.'stpl.class.php';
 		$this->scfg = &$scfg;
 		$this->stpl = &new stpl();
 		$this->stpl->assign("static",TPL_DIR."{static}");
 		$this->stpl->assign("SITE_DOMAIN",SITE_DOMAIN);	
 		$this->stpl->assign("NavMenu",$scfg["NavMenu"]);
 	}
 	/**
 	 * DB 相关
 	 * @param sting $key enum:member,goods,admin,msg,help
 	 */
    public static  $_db =array();
 	public function db($key='goods')
	{
		self::$_db[$key] || self::$_db[$key]   	= &new db($this->scfg['db'][$key]);
		return self::$_db[$key];
	}
}
# 檢查是否登錄
$urs  	= u_get_urs();
# 取得$_GET的参数
$class = $_REQUEST['c']?'Object'.$_REQUEST['c']:'ObjectIndex';
$method= $_REQUEST['a']?$_REQUEST['a']:$_REQUEST['act'];
$Pact  = $_REQUEST['p']?$_REQUEST['p']:$_REQUEST['Pact'];
if($Pact)
{
    $class .= 'Post';
    $method = &$Pact;
}
# 定義常量
define('urs',	$urs);
define('class',	$class);
define('method',$method);
/**
 * 功能:类与方法路由
 */
$filename = ROOT_DIR.$class.'.class.php';
if(file_exists($filename))
{
	include $filename;
	class_exists($class)
		|| E("NO_CLASS: <b>$class</b> ", 1);
	$Object = &new $class();
	if($method)
	{ 
		method_exists($Object,$method)
			|| E("THIS_CLASS: <b>$class</b>  NO_METHOD: <b>$method</b> ", 1);
		$Object->$method();
	}
}else
{
	E("NO_FILE: <b>$filename</b> ", 1);
}
?>